/*   1:    */ package tt.dz.web.controller.manager;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.util.ArrayList;
/*   5:    */ import java.util.HashMap;
/*   6:    */ import java.util.LinkedHashMap;
/*   7:    */ import java.util.List;
/*   8:    */ import java.util.Map;
/*   9:    */ import javax.annotation.Resource;
/*  10:    */ import org.springframework.stereotype.Controller;
/*  11:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  12:    */ import org.springframework.web.bind.annotation.RequestParam;
/*  13:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  14:    */ import tt.dz.biz.service.smsConfigure.SmsConfigureService;
/*  15:    */ import tt.dz.common.BusinessException;
import tt.dz.common.DzConstants;
/*  16:    */ import tt.dz.common.DzConstants.smsSendChannel;
import tt.dz.common.DzErrorCode;
/*  17:    */ import tt.dz.common.DzErrorCode.CommonErrorCode;
/*  18:    */ import tt.dz.common.LogUtil;
/*  19:    */ import tt.dz.vo.ResponseModle;
/*  20:    */ import tt.dz.vo.SmsConfigureVO;
/*  21:    */ import tt.dz.vo.SmsParameterShowVO;
/*  22:    */ 
/*  23:    */ @Controller
/*  24:    */ public class SmsConfigureManageController
/*  25:    */ {
/*  26:    */   @Resource(name="smsConfigureService")
/*  27:    */   private SmsConfigureService smsConfigureService;
/*  28:    */   
/*  29:    */   @RequestMapping(value={"/listSmsSendChannel"}, produces={"application/json;charset=UTF-8"})
/*  30:    */   @ResponseBody
/*  31:    */   public String listSmsSendChannel()
/*  32:    */   {
/*  33: 49 */     ResponseModle responseModle = null;
/*  34: 50 */     Map<String, Object> smsSendChannelListMap = new LinkedHashMap();
/*  35: 51 */     smsSendChannelListMap = DzConstants.smsSendChannel.getSmsSendChannelList();
/*  36: 52 */     responseModle = new ResponseModle("success", smsSendChannelListMap);
/*  37: 53 */     return JSON.toJSONString(responseModle);
/*  38:    */   }
/*  39:    */   
/*  40:    */   @RequestMapping(value={"/listAllSmsConfigure"}, produces={"application/json;charset=UTF-8"})
/*  41:    */   @ResponseBody
/*  42:    */   public String listAllSmsConfigure()
/*  43:    */   {
/*  44: 64 */     ResponseModle responseModle = null;
/*  45:    */     try
/*  46:    */     {
/*  47: 67 */       List<SmsConfigureVO> smsConfigureVOlist = this.smsConfigureService.getSmsConfigureVOlist();
/*  48: 69 */       for (SmsConfigureVO smsConfigureVO : smsConfigureVOlist)
/*  49:    */       {
/*  50: 70 */         Map<String, Object> paramMap = new HashMap();
/*  51: 71 */         paramMap.put("id", smsConfigureVO.getId().toString());
/*  52: 72 */         List<SmsParameterShowVO> smsParameterVOList = this.smsConfigureService.getSmsParameterVOList(paramMap);
/*  53: 73 */         smsConfigureVO.setSmsParameterVOList(smsParameterVOList);
/*  54:    */       }
/*  55: 75 */       responseModle = new ResponseModle("success", smsConfigureVOlist);
/*  56:    */     }
/*  57:    */     catch (Exception e)
/*  58:    */     {
/*  59: 77 */       LogUtil.error("查询所有短信配置信息", e);
/*  60: 78 */       responseModle = new ResponseModle("error", new ArrayList());
/*  61:    */     }
/*  62: 80 */     return JSON.toJSONString(responseModle);
/*  63:    */   }
/*  64:    */   
/*  65:    */   @RequestMapping(value={"/deleteSmsConfigure"}, produces={"application/json;charset=UTF-8"})
/*  66:    */   @ResponseBody
/*  67:    */   public String deleteSmsConfigure(@RequestParam(value="smsConfigureJSON", required=false) String smsConfigureJSON)
/*  68:    */   {
/*  69: 93 */     ResponseModle responseModle = null;
/*  70: 94 */     SmsConfigureVO smsConfigureVO = (SmsConfigureVO)JSON.parseObject(smsConfigureJSON, SmsConfigureVO.class);
/*  71: 95 */     Map<String, Object> paramMap = new HashMap();
/*  72: 96 */     paramMap.put("id", smsConfigureVO.getId().toString());
/*  73:    */     try
/*  74:    */     {
/*  75: 99 */       int result = this.smsConfigureService.deleteSmsConfigure(paramMap);
/*  76:100 */       responseModle = new ResponseModle("success", Integer.valueOf(result));
/*  77:    */     }
/*  78:    */     catch (Exception e)
/*  79:    */     {
/*  80:102 */       LogUtil.error("删除配置信息异常", e);
/*  81:103 */       responseModle = new ResponseModle("error", new ArrayList());
/*  82:    */     }
/*  83:    */     try
/*  84:    */     {
/*  85:107 */       int result = this.smsConfigureService.deleteSmsParameter(paramMap);
/*  86:108 */       responseModle = new ResponseModle("success", Integer.valueOf(result));
/*  87:    */     }
/*  88:    */     catch (Exception e)
/*  89:    */     {
/*  90:111 */       LogUtil.error("删除配置参数异常", e);
/*  91:112 */       responseModle = new ResponseModle("error", new ArrayList());
/*  92:    */     }
/*  93:114 */     return JSON.toJSONString(responseModle);
/*  94:    */   }
/*  95:    */   
/*  96:    */   @RequestMapping(value={"/saveSmsConfigure"}, produces={"application/json;charset=UTF-8"})
/*  97:    */   @ResponseBody
/*  98:    */   public String saveSmsConfigure(@RequestParam("smsConfigureJSON") String smsConfigureJSON, @RequestParam(value="smsParameterJSON", required=false) String smsParameterJSON)
/*  99:    */   {
/* 100:129 */     ResponseModle responseModle = null;
/* 101:130 */     SmsConfigureVO smsConfigureVO = null;
/* 102:131 */     List<SmsParameterShowVO> smsParameterVOList = null;
/* 103:133 */     if ((null != smsConfigureJSON) && (!smsConfigureJSON.isEmpty())) {
/* 104:134 */       smsConfigureVO = (SmsConfigureVO)JSON.parseObject(smsConfigureJSON, SmsConfigureVO.class);
/* 105:    */     }
/* 106:136 */     if ((null != smsParameterJSON) && (!smsParameterJSON.isEmpty())) {
/* 107:    */       try
/* 108:    */       {
/* 109:139 */         smsParameterVOList = parseStringToList(smsParameterJSON);
/* 110:    */       }
/* 111:    */       catch (BusinessException e)
/* 112:    */       {
/* 113:141 */         LogUtil.error("页面参数配置传入错误", e);
/* 114:142 */         responseModle = new ResponseModle("error", e.getExceptionMsg());
/* 115:143 */         return JSON.toJSONString(responseModle);
/* 116:    */       }
/* 117:    */     }
/* 118:146 */     if (null != smsConfigureVO) {
/* 119:    */       try
/* 120:    */       {
/* 121:148 */         int result = this.smsConfigureService.saveSmsConfigure(smsConfigureVO, smsParameterVOList);
/* 122:149 */         responseModle = new ResponseModle("success", Integer.valueOf(result));
/* 123:    */       }
/* 124:    */       catch (Exception e)
/* 125:    */       {
/* 126:151 */         LogUtil.error("保存平台配置一览异常", e);
/* 127:152 */         responseModle = new ResponseModle("error", "保存平台配置一览异常");
/* 128:    */       }
/* 129:    */     }
/* 130:155 */     return JSON.toJSONString(responseModle);
/* 131:    */   }
/* 132:    */   
/* 133:    */   private List<SmsParameterShowVO> parseStringToList(String smsParameterJSON)
/* 134:    */   {
/* 135:168 */     String str = smsParameterJSON.replaceAll("\"", "");
/* 136:169 */     String[] stringArr = str.split("&");
/* 137:170 */     List<SmsParameterShowVO> smsParameterVOList = new ArrayList();
/* 138:172 */     if (stringArr.length != 1)
/* 139:    */     {
/* 140:173 */       int size = 3;
/* 141:174 */       for (int i = 0; i < stringArr.length; i += size)
/* 142:    */       {
/* 143:175 */         SmsParameterShowVO smsParameterShowVO = new SmsParameterShowVO();
/* 144:176 */         for (int j = 0; j < size; j++)
/* 145:    */         {
/* 146:177 */           String[] stringArr2 = stringArr[(i + j)].split("=");
/* 147:178 */           if ((null != stringArr2) && (stringArr2.length > 0))
/* 148:    */           {
/* 149:179 */             String key = stringArr2[0];
/* 150:180 */             String value = " ";
/* 151:181 */             if (stringArr2.length == 1)
/* 152:    */             {
/* 153:182 */               DzErrorCode.CommonErrorCode ec = DzErrorCode.CommonErrorCode.PARAM_REQUIRED;
/* 154:183 */               throw new BusinessException(ec.value(), ec.getDesc(), "必传参数" + key + "不能为空");
/* 155:    */             }
/* 156:185 */             value = stringArr2[1];
/* 157:188 */             if ("paramName".equals(key)) {
/* 158:189 */               smsParameterShowVO.setParamName(value);
/* 159:    */             }
/* 160:191 */             if ("paramKey".equals(key)) {
/* 161:192 */               smsParameterShowVO.setParamKey(value);
/* 162:    */             }
/* 163:194 */             if ("paramValue".equals(key)) {
/* 164:195 */               smsParameterShowVO.setParamValue(value);
/* 165:    */             }
/* 166:    */           }
/* 167:    */         }
/* 168:199 */         smsParameterVOList.add(smsParameterShowVO);
/* 169:    */       }
/* 170:    */     }
/* 171:203 */     return smsParameterVOList;
/* 172:    */   }
/* 173:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.manager.SmsConfigureManageController
 * JD-Core Version:    0.7.0.1
 */